// pages/customer/customer_screen.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    staffIdAll:"",//选中的负责人id
    staffNameAll:"点击选择负责人",//选中的负责人名字
    selectId:[],//要查询的id,数组
    navScore_id:99,//分数导航id  99默认都不选
    start_points:0,//开始分数
    end_points:0,//结束分数
    chose:"",
    fromuid:"",
    code:"", //从哪个进来
    screenTypeData:[{
      id:1,
      selected:false,
      name:"客户"
    },{
      id:2,
      selected:false,
      name:"渠道商"
    },{
        id: 3,
        selected: false,
        name: "合作伙伴"
    },{
      id:4,
      selected:false,
      name:"其他"
    }], //类型数据
    screenLevelData:[{
      id:5,
      selected:false,
      name:"一般"
    },{
      id:6,
      selected:false,
      name:"重要"
    },{
      id:7,
      selected:false,
      name:"核心"
    }], //级别数据
    screenStateData:[{
      id:8,
      selected:false,
      name:"潜在"
    },{
      id:9,
      selected:false,
      name:"意向"
    },{
      id:10,
      selected:false,
      name:"洽谈"
    },{
      id:11,
      selected:false,
      name:"成交"
    },{
      id:12,
      selected:false,
      name:"流失"
    }], //状态数据
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      staffIdAll: options.staffIdAll,
      staffNameAll: options.staffNameAll,
      chose: options.chose,
      fromuid: options.fromuid,
      code:options.code,
      navScore_id:options.navScore_id,
      start_points:options.start_points,
      end_points:options.end_points,
    })
  },
  /*点击分数查询*/
  click_tabScore:function(e){
    this.setData({
      navScore_id:e.currentTarget.dataset.id,
      start_points:e.currentTarget.dataset.start_points,
      end_points:e.currentTarget.dataset.end_points,
    })

  },
  /*点击确定*/
  click_sure:function(){
    var that = this;
    let screenTypeData = that.data.screenTypeData;
    let screenLevelData = that.data.screenLevelData;
    let screenStateData = that.data.screenStateData;
    // 循环列表得到每个类型选中的数据
    let totalAll=[];
    for (let i = 0; i < screenTypeData.length; i++) {
      if (screenTypeData[i].selected) {
        totalAll.push(screenTypeData[i].id);
      }
    }
    for (let i = 0; i < screenLevelData.length; i++) {
      if (screenLevelData[i].selected) {
        totalAll.push(screenLevelData[i].id);
      }
    }
    for (let i = 0; i < screenStateData.length; i++) {
      if (screenStateData[i].selected) {
        totalAll.push(screenStateData[i].id);
      }
    }
    /*if(totalAll==""){
      wx.showToast({
        title: '还未选择要筛选的关键词',
        icon: 'none',
        duration: 2000
      })
    }else{


    }*/
    // 最后赋值到data中渲染到页面
    this.setData({
      selectId: totalAll
    });
    var chose ='';
    for (var i =0;i<totalAll.length;i++){
      chose += totalAll[i]+',' ;
    }
    chose = chose.slice(0, chose.length - 1)
    var fromuid = this.data.staffIdAll
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    prevPage.setData({
      fromuid: fromuid,
      chose: chose,
      navScore_id:this.data.navScore_id,
      start_points:this.data.start_points,
      end_points:this.data.end_points,
    })
    wx.navigateBack({
      delta: 1
    })
  },
  //类型点击事件
  selectType:function(e){
    let that=this;
    let index = e.currentTarget.dataset.index //当前选中的索引
    let screenTypeData = that.data.screenTypeData;
    //选中/未选中
    screenTypeData[index].selected = !screenTypeData[index].selected;
    // 重新渲染数据
    that.setData({
      screenTypeData:screenTypeData,
    })
  },
  //级别点击事件
  selectLevel:function(e){
    let that=this;
    let index = e.currentTarget.dataset.index //当前选中的索引
    let screenLevelData = that.data.screenLevelData;
    //选中/未选中
    screenLevelData[index].selected = !screenLevelData[index].selected;
    // 重新渲染数据
    that.setData({
      screenLevelData:screenLevelData,
    })
  },
  //状态点击事件
  selectState:function(e){
    let that=this;
    let index = e.currentTarget.dataset.index //当前选中的索引
    let screenStateData = that.data.screenStateData;
    //选中/未选中
    screenStateData[index].selected = !screenStateData[index].selected;
    // 重新渲染数据
    that.setData({
      screenStateData:screenStateData,
    })
  },
  /*清空*/
  del:function(){
    this.setData({
      navScore_id:99,//分数导航id
      start_points:0,//开始分数
      end_points:0,//结束分数
      staffIdAll: "",
      staffNameAll: "点击选择负责人",
      chose: "",
      fromuid: "",
      screenTypeData:[{
        id:1,
        selected:false,
        name:"客户"
      },{
        id:2,
        selected:false,
        name:"渠道商"
      },{
        id: 3,
        selected: false,
        name: "合作伙伴"
      },{
        id:4,
        selected:false,
        name:"其他"
      }], //类型数据
      screenLevelData:[{
        id:5,
        selected:false,
        name:"一般"
      },{
        id:6,
        selected:false,
        name:"重要"
      },{
        id:7,
        selected:false,
        name:"核心"
      }], //级别数据
      screenStateData:[{
        id:8,
        selected:false,
        name:"潜在"
      },{
        id:9,
        selected:false,
        name:"意向"
      },{
        id:10,
        selected:false,
        name:"洽谈"
      },{
        id:11,
        selected:false,
        name:"成交"
      },{
        id:12,
        selected:false,
        name:"流失"
      }], //状态数据
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh(); //停止下拉
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})